uniform sampler2D texture;
uniform sampler2D texture2;
uniform sampler2D distortion;
uniform sampler2D distortion2;

void main() {

    vec4 raw = texture2D( distortion, gl_TexCoord[0].xy );
    vec4 raw2 = texture2D( distortion2, gl_TexCoord[0].xy );

    if( raw.r > 0.0 && raw.r < 1.0 && raw.g > 0.0 && raw.g < 1.0 ) {
        vec4 pixel = texture2D( texture, gl_TexCoord[0].xy );
        vec4 pixel2 = texture2D( texture2, gl_TexCoord[0].xy );
        vec4 color = mix( vec4( 0.0, 0.0, 1.0, 1.0 ), vec4( 1.0, 0.0, 0.0, 1.0 ), pixel.x*pixel2.x );
        gl_FragColor = gl_Color*color*pixel*pixel2;
    } else {
        gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
    }
}
